/*     */ package com.qmsk.business.store.outstockbill.controller;
/*     */ 
/*     */ import com.qmsk.business.store.outstockbill.dao.OutStockBillDAO;
/*     */ import com.qmsk.business.store.outstockbill.service.OutStockBillService;
/*     */ import com.qmsk.business.store.outstockdtl.dao.OutStockDtlDAO;
/*     */ import com.utils.basic.MapUtils;
/*     */ import com.utils.gson.in.GsonHeadOneRow;
/*     */ import com.utils.gson.in.ParserDataSetJson;
/*     */ import com.utils.gson.out.GsonEbRst;
/*     */ import com.utils.jdbc.connection.DbConnection;
/*     */ import com.utils.web.RequestUtils;
/*     */ import com.utils.web.ResponseUtils;
/*     */ import java.sql.SQLException;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.apache.log4j.Logger;
/*     */ import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.transaction.annotation.Transactional;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"outStockBill"})
/*     */ public class OutStockBillController
/*     */ {
/*  33 */   private static final Logger logger = Logger.getLogger(OutStockBillController.class);
/*     */ 
/*     */   @Autowired
/*     */   private OutStockBillService service;
/*     */ 
/*     */   @Autowired
/*     */   private OutStockBillDAO dao;
/*     */ 
/*     */   @Autowired
/*     */   private OutStockDtlDAO dtlDao;
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/opt/{pageIdx}/{pageSize}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListOptShopId(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("pageIdx") Integer nPageIdx, @PathVariable("pageSize") Short nPageSize)
/*     */   {
/*  49 */     nPageSize = RequestUtils.getRequestValidPageSize(nPageSize);
/*     */     try {
/*  51 */       Map params = new HashMap();
/*  52 */       MapUtils.addToMap(params, "id", RequestUtils.getLong(request, "id"));
/*  53 */       GsonEbRst gsonEbRst = this.dao.getGsonOfAll(params, nPageIdx, nPageSize);
/*  54 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/*  56 */       logger.error(e);
/*  57 */       ResponseUtils.setErrorMsgResponse(
/*  58 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @RequestMapping(value={"find/shopId/{shopId}/id/{id}"}, method={org.springframework.web.bind.annotation.RequestMethod.GET})
/*     */   public void getListId(HttpServletRequest request, HttpServletResponse response, @PathVariable("id") Long id)
/*     */   {
/*     */     try {
/*  66 */       GsonEbRst gsonEbRst = this.dao.getGsonOfId(id);
/*  67 */       ResponseUtils.setResponseResult(gsonEbRst, response);
/*     */     } catch (Exception e) {
/*  69 */       logger.error(e);
/*  70 */       ResponseUtils.setErrorMsgResponse(
/*  71 */         RequestUtils.getFindDataErrorMessage(request), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"insert/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void insert(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId)
/*     */   {
/*     */     try
/*     */     {
/*  89 */       int nResult = 0;
/*  90 */       Long id = null;
/*  91 */       String billNo = null;
/*  92 */       String sData = RequestUtils.getStringOfData(request);
/*  93 */       String sInstoreDtl = RequestUtils.getString(request, "outStoreDtl");
/*  94 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/*  95 */       ParserDataSetJson p_dtl = ParserDataSetJson.fromString(sInstoreDtl);
/*  96 */       if ((p != null) && (p.isExistsInsertRows())) {
/*  97 */         billNo = this.dao.getMaxBillNo(shopId);
/*  98 */         for (GsonHeadOneRow g : p.getListInsertRows()) {
/*  99 */           g.autoAddHeadData("outNo", billNo);
/*     */         }
/*     */       }
/* 102 */       nResult = this.dao.applyUpdates(p, "id");
/* 103 */       if (nResult > 0) {
/* 104 */         id = (Long)((GsonHeadOneRow)p.getListInsertRows().get(0))
/* 105 */           .getValueOfName("id");
/* 106 */         for (GsonHeadOneRow r : p_dtl.getListInsertRows()) {
/* 107 */           r.autoAddHeadData("id", id);
/*     */         }
/* 109 */         nResult = this.dtlDao.applyUpdates(p_dtl);
/*     */       }
/* 111 */       if (nResult > 0) {
/* 112 */         DbConnection.commit();
/* 113 */         if (id != null) {
/* 114 */           String[] heads = { "id", "billNo" };
/* 115 */           Object[] datas = { id, billNo };
/* 116 */           ResponseUtils.toGsonEbRst(heads, datas, response);
/* 117 */           return; }
/* 118 */         ResponseUtils.setSqlResultResponse(nResult, 
/* 119 */           RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 120 */           response);
/*     */ 
/* 122 */         return; }
/* 123 */       DbConnection.rollback();
/* 124 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 125 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 126 */         response);
/*     */     }
/*     */     catch (Exception e) {
/* 129 */       logger.error(e);
/* 130 */       DbConnection.rollback();
/* 131 */       ResponseUtils.setErrorMsgResponse(
/* 132 */         RequestUtils.getSqlInsertDataErrorMessage(request) + ":" + 
/* 133 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"edit/shopId/{shopId}/{id}/{sendRange}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void edit(HttpServletRequest request, HttpServletResponse response, @PathVariable("shopId") Long shopId, @PathVariable("id") Long id, @PathVariable("sendRange") Integer sendRange)
/*     */   {
/*     */     try
/*     */     {
/* 152 */       int nResult = 0;
/* 153 */       String sData = RequestUtils.getStringOfData(request);
/* 154 */       ParserDataSetJson p = ParserDataSetJson.fromString(sData);
/* 155 */       if (p != null) {
/* 156 */         nResult = this.dao.applyUpdates(p);
/*     */       }
/* 158 */       if (nResult > 0)
/* 159 */         DbConnection.commit();
/*     */       else {
/* 161 */         DbConnection.rollback();
/*     */       }
/* 163 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 164 */         RequestUtils.getSqlInsertDataErrorMessage(request), 
/* 165 */         response);
/*     */     } catch (Exception e) {
/* 167 */       logger.error(e);
/* 168 */       DbConnection.rollback();
/* 169 */       ResponseUtils.setErrorMsgResponse(
/* 170 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 171 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"del/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void delete(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 187 */     String id = RequestUtils.getStringOfId(request);
/*     */     try {
/* 189 */       String[] strParams = id.split(",");
/* 190 */       int nResult = this.dao.deleteParams(strParams);
/* 191 */       if (nResult > 0)
/* 192 */         DbConnection.commit();
/*     */       else {
/* 194 */         DbConnection.rollback();
/*     */       }
/* 196 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 197 */         RequestUtils.getSqlDeleteDataErrorMessage(request), 
/* 198 */         response);
/*     */     } catch (Exception e) {
/* 200 */       DbConnection.rollback();
/* 201 */       logger.error(e);
/* 202 */       ResponseUtils.setErrorMsgResponse(
/* 203 */         RequestUtils.getSqlDeleteDataErrorMessage(request) + ":" + 
/* 204 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ 
/*     */   @Transactional
/*     */   @RequestMapping(value={"check/shopId/{shopId}"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
/*     */   public void check(HttpServletRequest request, HttpServletResponse response)
/*     */     throws SQLException
/*     */   {
/* 222 */     int nResult = 0;
/* 223 */     Long id = RequestUtils.getLong(request, "id");
/*     */     try {
/* 225 */       nResult = this.service.check(id, response).intValue();
/* 226 */       if (nResult > 0)
/* 227 */         DbConnection.commit();
/*     */       else {
/* 229 */         DbConnection.rollback();
/*     */       }
/* 231 */       ResponseUtils.setSqlResultResponse(nResult, 
/* 232 */         RequestUtils.getSqlUpdateDataErrorMessage(request), 
/* 233 */         response);
/*     */     } catch (Exception e) {
/* 235 */       DbConnection.rollback();
/* 236 */       logger.error(e);
/* 237 */       ResponseUtils.setErrorMsgResponse(
/* 238 */         RequestUtils.getSqlUpdateDataErrorMessage(request) + ":" + 
/* 239 */         e.getMessage(), response);
/*     */     }
/*     */   }
/*     */ }

/* Location:           C:\Users\Administrator\Desktop\新建文件夹\WEB-INF\classes\
 * Qualified Name:     com.qmsk.business.store.outstockbill.controller.OutStockBillController
 * JD-Core Version:    0.5.3
 */